﻿<Page x:Class="VRacer.Pages.Highscores"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:common="clr-namespace:VRacer;assembly=VRacer"
      xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    Title="Highscores">

    <Page.Resources>
        <DataTemplate DataType="{x:Type common:Score}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="Player" />
                    <ColumnDefinition SharedSizeGroup="Score" />
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0" Text="{Binding Player}" />
                <TextBlock Grid.Column="1" Text="{Binding Result}" />
            </Grid>
        </DataTemplate>
    </Page.Resources>


    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="310" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <ListBox Grid.Column="0" Name="_tracks" ItemsSource="{Binding}" />
        <Border Margin="10" Grid.Column="1">
            <Border.Resources>
                <CollectionViewSource Source="{Binding SelectedValue.Highscores, ElementName=_tracks}" x:Key="cvs" >
                    <CollectionViewSource.SortDescriptions>
                        <scm:SortDescription Direction="Ascending" PropertyName="Result"/>
                    </CollectionViewSource.SortDescriptions>
                </CollectionViewSource>
            </Border.Resources>
            <StackPanel>
                <Label HorizontalAlignment="Center" FontWeight="Bold" FontSize="25">Highscores</Label>
                <ScrollViewer VerticalScrollBarVisibility="Auto">
                    <Grid Grid.IsSharedSizeScope="True">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="200" SharedSizeGroup="Player" />
                            <ColumnDefinition SharedSizeGroup="Score" />
                        </Grid.ColumnDefinitions>

                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>

                        <TextBlock Grid.Column="0" FontWeight="Bold">Player</TextBlock>
                        <TextBlock Grid.Column="1" FontWeight="Bold">Score</TextBlock>
                        <ItemsControl Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding Source={StaticResource cvs}}" />
                    </Grid>
                </ScrollViewer>
            </StackPanel>
        </Border>
    </Grid>
</Page>
